<HTML><HEAD><TITLE>weight(+Graph, +WeightHash, ?Weight)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">library(grasper)</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>weight(+Graph, +WeightHash, ?Weight)</H1>
Calculates the Weight of Graph given a WeightHash.
<DL>
<DT><EM>Graph</EM></DT>
<DD>A graph.
</DD>
<DT><EM>WeightHash</EM></DT>
<DD>An hashtable an hashtable matching some elements (vertex or edge) of Graph to a positive weight. An unweighed element will be considered to have weight 0.
</DD>
<DT><EM>Weight</EM></DT>
<DD>The sum of the graph's vertices' and edges' weights.
</DD>
</DL>
<H2>Description</H2>
Calculates the Weight of Graph given a WeightHash.
<H3>Fail Conditions</H3>
Fails
			 if Graph is not a graph variable,
			 if Weight is not an hash variable (lib(hash)) with positive integer weights or
			 if Graph can not be constrained to have a weight delimited by Weight.
			
<H2>Examples</H2>
<PRE>
?- weight(G,WH,W).
No.
 
?- V`::[]..[1,2,3], E`::[]..[[1,2],[2,3],[3,1]], dirgraph(G,V,E), weight(G,WH,W).
instantiation fault in term_hash(1, -1, Size, _2486)
Abort
 
?- V`::[]..[1,2,3], E`::[[1,2]]..[[1,2],[2,3],[3,1]], dirgraph(G,V,E), hash_create(WH), hash_add(WH,1,1), hash_add(WH,2,1), hash_add(WH,3,1), hash_add(WH,[1,2],1), hash_add(WH,[2,3],1), hash_add(WH,[3,1],1), weight(G,WH,0).
No.
 
?- V`::[]..[1,2,3], E`::[[1,2]]..[[1,2],[2,3],[3,1]], dirgraph(G,V,E), hash_create(WH), hash_add(WH,1,1), hash_add(WH,2,1), hash_add(WH,3,1), hash_add(WH,[1,2],1), hash_add(WH,[2,3],1), hash_add(WH,[3,1],1), weight(G,WH,7).
No.
 
?- V`::[]..[1,2,3], E`::[[1,2]]..[[1,2],[2,3],[3,1]], dirgraph(G,V,E), hash_create(WH), hash_add(WH,1,1), hash_add(WH,2,1), hash_add(WH,3,1), hash_add(WH,[1,2],1), hash_add(WH,[2,3],1), hash_add(WH,[3,1],1), weight(G,WH,W).
V = V{cardinal([[1, 2] : 2, [3] : 3], Card{cardinal : _941, fd : [2, 3]}, _833, _834, _835, [], ['SUSP-_3104-susp'], ['SUSP-_3130-susp', 'SUSP-_2731-susp'], ['SUSP-_2355-dead'])}
E = E{cardinal([[[1, 2]] : 1, [[2, 3], [3, 1]] : 3], Card{cardinal : _1131, fd : [1 .. 3]}, _1023, _1024, _1025, [], ['SUSP-_3117-susp', 'SUSP-_2741-susp'], ['SUSP-_3143-susp'], ['SUSP-_2049-dead'])}
G = dirgraph(V{cardinal([[1, 2] : 2, [3] : 3], Card{cardinal : _941, fd : [2, 3]}, _833, _834, _835, [], ['SUSP-_3104-susp'], ['SUSP-_3130-susp', 'SUSP-_2731-susp'], ['SUSP-_2355-dead'])}, E{cardinal([[[1, 2]] : 1, [[2, 3], [3, 1]] : 3], Card{cardinal : _1131, fd : [1 .. 3]}, _1023, _1024, _1025, [], ['SUSP-_3117-susp', 'SUSP-_2741-susp'], ['SUSP-_3143-susp'], ['SUSP-_2049-dead'])})
WH = hash(4, 6, [[3, 1] -&gt; 1, [2, 3] -&gt; 1, 1 -&gt; 1, 2 -&gt; 1, [1, 2] -&gt; 1, 3 -&gt; 1])
W = W{cardinal : _3033, fd : [3 .. 6]}
 
?- V`::[]..[1,2,3], E`::[[1,2]]..[[1,2],[2,3],[3,1]], dirgraph(G,V,E), hash_create(WH), hash_add(WH,1,1), hash_add(WH,2,1), hash_add(WH,3,1), hash_add(WH,[1,2],1), hash_add(WH,[2,3],1), hash_add(WH,[3,1],1), weight(G,WH,3).
V = [1, 2]
E = [[1, 2]]
G = dirgraph([1, 2], [[1, 2]])
WH = hash(4, 6, [[3, 1] -&gt; 1, [2, 3] -&gt; 1, 1 -&gt; 1, 2 -&gt; 1, [1, 2] -&gt; 1, 3 -&gt; 1])
 
?- V`::[]..[1,2,3], E`::[[1,2]]..[[1,2],[2,3],[3,1]], dirgraph(G,V,E), hash_create(WH), hash_add(WH,1,1), hash_add(WH,2,1), hash_add(WH,3,1), hash_add(WH,[1,2],1), hash_add(WH,[2,3],1), hash_add(WH,[3,1],1), weight(G,WH,6).
V = [1, 2, 3]
E = [[1, 2], [2, 3], [3, 1]]
G = dirgraph([1, 2, 3], [[1, 2], [2, 3], [3, 1]])
WH = hash(4, 6, [[3, 1] -&gt; 1, [2, 3] -&gt; 1, 1 -&gt; 1, 2 -&gt; 1, [1, 2] -&gt; 1, 3 -&gt; 1])
			</PRE>

</BODY></HTML>
